package com.cyc.controller;

import com.cyc.model.Information;
import com.cyc.service.InfomationService;
import com.cyc.tools.Layui;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("/admin")
public class InformationController {
    @Resource
    private InfomationService informationService;
    @GetMapping("/information")
    public String result(){
        return "information";
    }

    @ResponseBody
    @RequestMapping(value = "/AllInfo")
    public Layui all(@RequestParam(value = "page") Integer page,
                     @RequestParam(value = "size") Integer size){
        return informationService.getAll(page,size);
    }
    //学生信息搜索
    @ResponseBody
    @RequestMapping(value = "/InfoSearch", method = RequestMethod.POST)
    public Layui search(Information information,
                        @RequestParam(value = "page") Integer page,
                        @RequestParam(value = "size") Integer size) {
        return informationService.search(information,page,size);
    }

    //添加/修改一个学生信息
    @ResponseBody
    @RequestMapping(value = "/addOrEdit", method = RequestMethod.POST)
    public Layui add(Information information) {
        //先添加/编辑再返回表格
        int i = informationService.addOrEditOne(information);
        if(i>0){
            return informationService.getAll(1, 10);
        }
        return null;
    }
    //删除
    @ResponseBody
    @RequestMapping(value = "/delOne",method = RequestMethod.POST)
    public Layui del(Information information){
        int i = informationService.delOne(information);
        if(i>0){
            return informationService.getAll(1,10);
        }
        return null;
    }
}
